package com.sdk.bigdata.model;


import com.alibaba.fastjson.annotation.JSONField;
import com.sdk.bigdata.exceptions.DataException;

import java.util.HashMap;
import java.util.Map;

// 用户行为事件
public class Entity extends BaseModel {
    private String entity;

    @JSONField(name = "entity_id")
    private String entityId;

    public Entity(String type,String entity, String entityId, Map<String, Object> properties) {
        super(type,properties);
        this.entity = entity;
        this.entityId = entityId;
    }

    public Entity(){}

    public String getEntity() {
        return entity;
    }

    public void setEntity(String entity) {
        this.entity = entity;
    }

    public String getEntityId() {
        return entityId;
    }

    public void setEntityId(String entityId) {
        this.entityId = entityId;
    }

    @Override
    public void validAttribute() {
        this.setTime(System.currentTimeMillis());
        this.setType("entity");
        // check uid
        if (null == this.getEntityId() || this.getEntityId().equals("")) {
            throw new DataException("property [EntityId] can't be empty");
        }
        if (this.getEntityId().length() > 255) {
            throw new DataException("the max length of property [uid] is 255");
        }
        // check model
        if (null == this.getEntity() || this.getEntity().equals("")) {
            throw new DataException("entity name can't be empty");
        }

        if (null == this.getProperties()) {
            this.setProperties(new HashMap<>());
        }
    }
}
